home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- Windows Sockets Client Application Support Module
-
- Written by:
- John A. Junod Internet: <junodj@gordon-emh2.army.mil>
- 267 Hillwood Street <zj8549@trotter.usma.edu>
- Martinez, GA 30907 Compuserve: 72321,366
-
- This program executable and all source code is released into the public
- domain. It would be nice (but is not required) to give me a little
- credit for any use of this code.
-
- THE INFORMATION AND CODE PROVIDED IS PROVIDED AS IS WITHOUT WARRANTY
- OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE. IN NO EVENT SHALL JOHN A. JUNOD BE LIABLE FOR ANY DAMAGES
- WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS
- OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF JOHN A. JUNOD HAS BEEN
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
- *****************************************************************************/
-
- #include "ws_glob.h"
- #include "ws_ftp.h"
-
- #define MAXHOSTS 20
- char szInitDir[80];
-
-
- struct HOSTINFO {
- HANDLE hostname;
- HANDLE userid;
- HANDLE password;
- HANDLE initdir;
- int hosttype;
- int sendsize;
- int recvsize;
- u_int timeout;
- };
-
- HANDLE HostInfo[MAXHOSTS];
-
- // int nTypes[MAXHOSTS];
- BOOL bSaveUID=FALSE;
- BOOL bSavePWD=FALSE;
- char szCrypt[160];
- LPSTR szAnony="anonymous";
- int nHostType=0;
- extern BOOL bHELP;
- extern BOOL bCanMKD,bCanRMD,bCanREN,bCanDELE;
- extern HBRUSH hbrGray1,hbrGray2;
-
- /*
- // this encryption is not secure nor is it intended to be
- // this is just to keep the password from being plain text
- // in the ini file. I'd really recommend people don't save
- // their passwords
- */
- LPSTR EnCrypt(LPSTR userid,LPSTR passwd)
- {
- int nIndex;
- if(lstrcmp(userid,szAnony)==0)
- return(passwd);
- szCrypt[0]=0;
- for(nIndex=0;nIndex<lstrlen(passwd);nIndex++) {
- wsprintf(&szCrypt[nIndex*2],"%02X",
- ((char)passwd[nIndex])+nIndex);
- }
- return(szCrypt);
- }
-
- int unhex(char c) {
- if(c>'9') return(c-'7');
- return (c-'0');
- }
-
- LPSTR DeCrypt(LPSTR userid,LPSTR passwd)
- {
- int nIndex;
- if(lstrcmp(userid,szAnony)==0)
- return(passwd);
- szCrypt[0]=0;
- for(nIndex=0;nIndex<lstrlen(passwd);nIndex+=2) {
- (BYTE)szCrypt[nIndex/2]=
- ((unhex(passwd[nIndex])*16)+
- unhex(passwd[nIndex+1]))-(nIndex/2);
- szCrypt[nIndex/2+1]=0;
- }
- return(szCrypt);
- }
-
- /*************************************************************
- allocate global memory and copy the string into the memory
- */
- HANDLE SaveOne(LPSTR lpszSrc)
- {
- HANDLE pGlobal;
-
- if(lpszSrc==NULL || strlen(lpszSrc)==0) return(NULL);
-
- if((pGlobal=GlobalAlloc(LHND,lstrlen(lpszSrc)+1))!=NULL){
- strcpy(GlobalLock(pGlobal),lpszSrc);
- GlobalUnlock(pGlobal);
- }
- return(pGlobal);
- }
-
- /*************************************************************
- get a string from global memory
- */
- void GetOne(LPSTR lpszDest,HANDLE pGlobal)
- {
- if(pGlobal) {
- strcpy(lpszDest,GlobalLock(pGlobal));
- GlobalUnlock(pGlobal);
- } else *lpszDest=0;
- }
-
- /*************************************************************
- create our host information structure in global memory
- */
- HANDLE MakeInfo(LPSTR hostname,LPSTR userid,LPSTR password,LPSTR initdir,
- int hosttype,int sendsize,int recvsize,u_int timeout)
- {
- HANDLE pGlobal;
- struct HOSTINFO *pHost;
- if((pGlobal=GlobalAlloc(LHND,sizeof(struct HOSTINFO)))!=NULL) {
- pHost=(struct HOSTINFO *)GlobalLock(pGlobal);
- pHost->hostname=SaveOne(hostname);
- pHost->userid=SaveOne(userid);
- pHost->password=SaveOne(password);
- pHost->initdir=SaveOne(initdir);
- pHost->hosttype=hosttype;
- pHost->sendsize=sendsize;
- pHost->recvsize=recvsize;
- pHost->timeout=timeout;
- GlobalUnlock(pGlobal);
- }
- return(pGlobal);
- }
-
- /*************************************************************
- release a global memory host information structure
- */
- void FreeInfo(HANDLE pGlobal)
- {
- struct HOSTINFO *pHost;
- if(pGlobal && (pHost=(struct HOSTINFO *)GlobalLock(pGlobal))!=NULL) {
- if(pHost->hostname) GlobalFree(pHost->hostname);
- if(pHost->userid) GlobalFree(pHost->userid);
- if(pHost->password) GlobalFree(pHost->password);
- if(pHost->initdir) GlobalFree(pHost->initdir);
- GlobalUnlock(pGlobal);
- GlobalFree(pGlobal);
- }
- }
-
- /****************************************************************
- get the information from a global memory host info structure
- */
- BOOL GetInfo(HANDLE pGlobal,LPSTR hostname,LPSTR userid,
- LPSTR password,LPSTR initdir,
- int *hosttype,int *sendsize,int *recvsize,u_int *timeout)
- {
- struct HOSTINFO *pHost;
- if(pGlobal && (pHost=(struct HOSTINFO *)GlobalLock(pGlobal))!=NULL) {
- if(hostname) GetOne(hostname,pHost->hostname);
- if(userid) GetOne(userid ,pHost->userid);
- if(password) GetOne(password,pHost->password);
- if(initdir) GetOne(initdir ,pHost->initdir);
- if(hosttype) *hosttype=pHost->hosttype;
- if(sendsize) *sendsize=pHost->sendsize;
- if(recvsize) *recvsize=pHost->recvsize;
- if(timeout) *timeout =pHost->timeout;
- GlobalUnlock(pGlobal);
- return(TRUE);
- }
- return(FALSE);
- }
-
- /***************************************************************
- compare a hostname to a global memory host info structure
- */
- BOOL CompareHost(LPSTR lpszHost,HANDLE pGlobal)
- {
- BOOL retcode=FALSE;
- char Hostname[120];
- if(GetInfo(pGlobal,Hostname,NULL,NULL,NULL,NULL,NULL,NULL,NULL))
- if(lstrcmpi(Hostname,lpszHost)==0) retcode=TRUE;
- return(retcode);
- }
-
- /*******************************************************
- Set the dialog box controls according to the current
- selected host.
- */
- SetDefaultHostStuff(HWND hWndDlg,LPSTR szRHost) {
- int nIndex;
- struct HOSTINFO *pHost;
- LPSTR pUserid,pPasswd,pStr;
-
- for(nIndex=0;nIndex<MAXHOSTS;nIndex++)
- if(CompareHost(szRHost,HostInfo[nIndex])&&
- (pHost=(struct HOSTINFO *)GlobalLock(HostInfo[nIndex]))!=NULL) {
- if(pHost->userid && (pUserid=GlobalLock(pHost->userid))!=NULL) {
- SetDlgItemText(hWndDlg,DLG_EDT_USERID,pUserid);
- if(lstrcmpi(pUserid,szAnony)==0)
- CheckDlgButton(hWndDlg,DLG_HOST_ANONY,TRUE);
- else
- CheckDlgButton(hWndDlg,DLG_HOST_ANONY,FALSE);
- if(pHost->userid && (pPasswd=GlobalLock(pHost->password))!=NULL) {
- SetDlgItemText(hWndDlg,DLG_EDT_PASSWD,DeCrypt(pUserid,pPasswd));
- GlobalUnlock(pHost->password);
- CheckDlgButton(hWndDlg,DLG_HOST_PWD,TRUE);
- } else {
- if(lstrcmpi(pUserid,szAnony)==0) {
- if(*szMailAddress==0)
- StdInput(szMailAddress,"Enter your e-mail address:");
- SetDlgItemText(hWndDlg,DLG_EDT_PASSWD,szMailAddress);
- } else SetDlgItemText(hWndDlg,DLG_EDT_PASSWD,"");
- CheckDlgButton(hWndDlg,DLG_HOST_PWD,FALSE);
- }
- GlobalUnlock(pHost->userid);
- } else {
- SetDlgItemText(hWndDlg,DLG_EDT_USERID,"");
- SetDlgItemText(hWndDlg,DLG_EDT_PASSWD,"");
- }
- CheckRadioButton(hWndDlg,DLG_HOST_AUTO,DLG_HOST_U5000,6000+pHost->hosttype);
- if(pHost->initdir && (pStr=GlobalLock(pHost->initdir))!=NULL) {
- SetDlgItemText(hWndDlg,DLG_HOST_DIR,pStr);
- GlobalUnlock(pHost->initdir);
- } else {
- SetDlgItemText(hWndDlg,DLG_HOST_DIR,"");
- }
- SetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,pHost->timeout,FALSE);
- GlobalUnlock(HostInfo[nIndex]);
- break;
- }
- return TRUE;
- }
-
- /******************************************************************
- Message processing for host dialog box
- */
- BOOL FAR PASCAL WS_HostMsgProc(HWND hWndDlg, WORD Message,
- WORD wParam, LONG lParam)
- {
- int nIndex;
- char szRHost[80];
- UINT nRC;
-
- switch(Message)
- {
- case WM_INITDIALOG:
- for(nIndex=0;nIndex<MAXHOSTS;nIndex++)
- if(HostInfo[nIndex] && GetInfo(HostInfo[nIndex],szRHost,NULL,
- NULL,NULL,NULL,NULL,NULL,NULL))
- SendDlgItemMessage(hWndDlg,DLG_EDT_HOST,CB_ADDSTRING,
- 0,(long)szRHost);
- SetDlgItemText(hWndDlg,DLG_EDT_HOST,szRemoteHost);
- SetDlgItemText(hWndDlg,DLG_EDT_USERID,szUserID);
- SetDlgItemText(hWndDlg,DLG_EDT_PASSWD,szPassWord);
- SetDlgItemText(hWndDlg,DLG_HOST_DIR,szInitDir);
- SetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,uiTimeOut,FALSE);
- CheckDlgButton(hWndDlg,DLG_HOST_PWD,bSavePWD);
- CheckRadioButton(hWndDlg,DLG_HOST_AUTO,DLG_HOST_U5000,6000+nHostType);
- strcpy(szRHost,szRemoteHost);
- SetDefaultHostStuff(hWndDlg,szRHost);
- cwCenter(hWndDlg, 0);
- SendDlgItemMessage(hWndDlg,DLG_EDT_HOST,WM_SETREDRAW,TRUE,0l);
- break;
- case WM_CLOSE:
- PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
- break;
- case WM_CTLCOLOR:
- switch(HIWORD(lParam)) {
- case CTLCOLOR_BTN:
- if(LOWORD(lParam)<10) return((LRESULT)NULL);
- case CTLCOLOR_DLG:
- case CTLCOLOR_STATIC:
- SetBkColor((HDC) wParam, RGB(192,192,192));
- return(LRESULT)hbrGray1;
- }
- return(LRESULT)NULL;
-
- case WM_COMMAND:
- switch(wParam)
- {
- case DLG_EDT_HOST:
- if(HIWORD(lParam)==CBN_KILLFOCUS ||
- HIWORD(lParam)==CBN_EDITCHANGE) {
- GetDlgItemText(hWndDlg,DLG_EDT_HOST,szRHost,70);
- } else if(HIWORD(lParam)==CBN_SELCHANGE) {
- if((nIndex=SendDlgItemMessage(hWndDlg,DLG_EDT_HOST,
- CB_GETCURSEL,0,0L))!=LB_ERR)
- SendDlgItemMessage(hWndDlg,DLG_EDT_HOST,CB_GETLBTEXT,
- nIndex,(LONG)szRHost);
- else break;
- } else break;
- SetDefaultHostStuff(hWndDlg,szRHost);
- break;
-
- case DLG_HOST_ANONY:
- if(IsDlgButtonChecked(hWndDlg,DLG_HOST_ANONY)) {
- SetDlgItemText(hWndDlg,DLG_EDT_USERID,szAnony);
- if(*szMailAddress==0)
- StdInput(szMailAddress,"Enter your e-mail address:");
- SetDlgItemText(hWndDlg,DLG_EDT_PASSWD,szMailAddress);
- }
- return(FALSE);
- case DLG_HOST_PWD:
- case DLG_HOST_SAVE:
- if(!IsDlgButtonChecked(hWndDlg,DLG_HOST_SAVE))
- CheckDlgButton(hWndDlg,DLG_HOST_PWD,FALSE);
- return(FALSE);
- case IDOK:
- GetDlgItemText(hWndDlg,DLG_EDT_HOST,szRemoteHost,70);
- GetDlgItemText(hWndDlg,DLG_EDT_USERID,szUserID,15);
- GetDlgItemText(hWndDlg,DLG_EDT_PASSWD,szPassWord,50);
- GetDlgItemText(hWndDlg,DLG_HOST_DIR,szInitDir,79);
- nRC=GetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,NULL,FALSE);
- if(nRC==0) uiTimeOut=65; else uiTimeOut=nRC;
- if(uiTimeOut > (65536/1000)) uiTimeOut=65530/1000;
- bSavePWD=FALSE;
- if(IsDlgButtonChecked(hWndDlg,DLG_HOST_PWD))
- bSavePWD=TRUE;
- else
- bSavePWD=FALSE;
- nHostType=0;
- for(nIndex=1;nIndex<=DLG_HOST_U5000;nIndex*=2)
- if(IsDlgButtonChecked(hWndDlg,6000+nIndex))
- nHostType=nIndex;
- EndDialog(hWndDlg, TRUE);
- break;
- case IDCANCEL:
- EndDialog(hWndDlg, FALSE);
- break;
- }
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
-
- /***************************************************************
- save the information about the current host in the array of
- host information. Called from connect routine.
- */
- void SaveHostName(LPSTR szRemoteHost,LPSTR szUserid,LPSTR szPassword)
- {
- int nIndex;
- BOOL bFound=FALSE;
- struct HOSTINFO *pHost;
-
- for(nIndex=0;nIndex<MAXHOSTS;nIndex++)
- if(CompareHost(szRemoteHost,HostInfo[nIndex])&&
- ((LPSTR)pHost=GlobalLock(HostInfo[nIndex]))!=NULL) {
- bFound=TRUE;
- if(pHost->userid) GlobalFree(pHost->userid);
- if(pHost->password) GlobalFree(pHost->password);
- if(pHost->initdir) GlobalFree(pHost->initdir);
- pHost->userid=SaveOne(szUserid);
- if(bSavePWD)
- pHost->password=SaveOne(EnCrypt(szUserid,szPassword));
- else
- pHost->password=NULL;
- pHost->initdir=SaveOne(szInitDir);
- pHost->hosttype=nHostType;
- pHost->timeout=uiTimeOut;
- GlobalUnlock(HostInfo[nIndex]);
- }
-
- if(!bFound) {
- FreeInfo(HostInfo[MAXHOSTS-1]);
- for(nIndex=(MAXHOSTS-1);nIndex>0;nIndex--)
- HostInfo[nIndex]=HostInfo[nIndex-1];
- HostInfo[0]=MakeInfo(szRemoteHost,szUserid,
- (bSavePWD?EnCrypt(szUserid,szPassword):NULL),
- szInitDir,nHostType,1024,1024,uiTimeOut);
- }
- }
-
- /*****************************************************
- convert remotename into something DOS can deal with
- */
- MakeLocalName(LPSTR localname,LPSTR remotename)
- {
- int nIndex;
- char Name[10],Ext[4],*s;
-
- while(*remotename!=0 && *remotename=='.')
- remotename++;
- for(nIndex=0;nIndex<8;nIndex++)
- if(*remotename!=0 && *remotename!='.' && *remotename!=' ')
- Name[nIndex] = *remotename++;
- else break;
- Name[nIndex]=0; Ext[0]=0;
- if((s=strchr(remotename,'.'))!=NULL)
- remotename=s;
- while(*remotename!=0 && (*remotename=='.' || *remotename==' '))
- remotename++;
- if(*remotename!=0) {
- for(nIndex=0;nIndex<3;nIndex++)
- if(*remotename!=0 && *remotename!='.' && *remotename!=' ')
- Ext[nIndex] = *remotename++;
- else break;
- Ext[nIndex]=0;
- }
- if(Ext[0]==0) {
- lstrcpy(localname,Name);
- } else {
- wsprintf(localname,"%s.%s",Name,Ext);
- }
-
- if(lstrlen(localname)==0) {
- lstrcpy(Name,"aaremote");
- lstrcpy(localname,Name);
- }
-
- if(bRecvUniq) {
- nIndex=0;
- while((int)access(localname,0)==0 && nIndex<99) {
- DoPrintf("[recvuniq] %s - %s - %s",Name,Ext,localname);
- if(Ext[0]==0)
- wsprintf(localname,"%s.%03u",Name,nIndex);
- else if(lstrlen(Name)>5)
- wsprintf(localname,"%-5.5s%03u.%s",Name,nIndex,Ext);
- else wsprintf(localname,"%s%03u.%s",Name,nIndex,Ext);
- nIndex++;
- }
- }
- return(TRUE);
- }
-
- /*************************************************
- find filename in a UNIX directory listing
- */
- LPSTR FindName(LPSTR szLine)
- {
- int nIndex;
- char *pStr;
-
- // strip trailing garbage from the line if there is any.
- while((nIndex=strlen(szLine))>2 &&
- (szLine[nIndex-1]==0x0a || szLine[nIndex-1]==0x0d ||
- szLine[nIndex-1]==' ' || szLine[nIndex-1]==0x09))
- szLine[nIndex]=0;
-
- // now the name SHOULD be the last thing on the line
- if((pStr=strrchr(szLine,' '))!=NULL ||
- (pStr=strrchr(szLine,0x09))!=NULL) {
- while(*pStr && (*pStr==' ' || *pStr==0x09)) pStr++;
- return(pStr);
- }
- return(szLine);
- }
-
- /*****************************************************************
- This is the routine that take the output from LIST and breaks
- it down into files and directories. The format for the output
- from most of the machine types was provided by Chris Sacksteder.
- */
- int GetRemoteDirForWnd(HWND hWnd)
- {
- char *pStr,*s;
- FILE *fd;
- int nRC;
-
- // clean out the old contents of the list boxes
- SendMessage(hLbxRDir,LB_RESETCONTENT,0,0);
- SendMessage(hLbxRFiles,LB_RESETCONTENT,0,0);
- // can't do much if we aren't connected
- if(!bConnected) {
- SendMessage(hTxtRDir,WM_SETTEXT,0,(LPARAM)"");
- // SendMessage(hTxtStatus,WM_SETTEXT,0,
- // (LPARAM)"not connected to remote host");
- }
- else {
- // get the remote directory name
- strcpy(szString,"undecipherable");
- nRC=DoPWD(ctrl_socket);
- if(nRC==FTP_COMPLETE) {
- if((pStr=strchr(szMsgBuf,'"'))!=NULL)
- strncpy(szString,++pStr,180);
- if((pStr=strchr(szString,'"'))!=NULL)
- *pStr=0;
- else szString[180]=0;
- }
- SendMessage(hTxtRDir,WM_SETTEXT,0,(LPARAM)szString);
- // if we haven't done it already then go try to determine
- // host type and what are valid functions.
- if(!bHELP) ReadProcessHelp(ctrl_socket);
- // go get the current remote directory listing in tmpfile.tmp
- nRC=DoDirList(ctrl_socket,"LIST");
-
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LPARAM)"..");
- if(nRC==FTP_COMPLETE) {
- if((fd=fopen(szTmpFile,"r"))!=NULL) {
- while(fgets(szString,180,fd)!=NULL) {
- if((pStr=strchr(szString,'\n'))!=NULL) *pStr=0;
- switch(nHostType+6000) {
- case DLG_HOST_SUPER:
- case DLG_HOST_CHAMELEON:
- case DLG_HOST_NCSA:
- if(strstr(szString,"<DIR>")!=NULL) {
- if((pStr=strchr(szString,' '))!=NULL) *pStr=0;
- if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
- } else {
- if((pStr=strchr(szString,' '))!=NULL) *pStr=0;
- if(szString[0]!=0)
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
- }
- break;
- case DLG_HOST_QVT:
- if(szString[strlen(szString)-1]=='/' ||
- szString[strlen(szString)-1]=='\\')
- {
- szString[strlen(szString)-1]=0;
- if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
- } else
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
- break;
- case DLG_HOST_IBM_VM:
- szString[12]=0;
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
- break;
- case DLG_HOST_VMS_UCX:
- case DLG_HOST_VMS_MULTINET:
- if(*szString!=' ') {
- if((s=strchr(szString,';'))!=NULL) {
- if(strlen(szString)>4 &&
- strcmp(&szString[strlen(szString)-4],".DIR")==0) {
- *s=0;
- szString[strlen(szString)-4]=0;
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
- } else {
- if((s=strchr(szString,' '))!=NULL) *s=0;
- if((s=strchr(szString,'\t'))!=NULL) *s=0;
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
- }
- }
- }
- break;
- case DLG_HOST_PCTCP:
- szString[30]=0; s=FindName(szString);
- if(strncmp(szString,"<dir>",5)==0) {
- if(strcmp(s,".")!=0 && strcmp(s,"..")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)s);
- } else
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)s);
- break;
- case DLG_HOST_IBM_TCP:
- s=FindName(szString);
- if(strstr(szString," DIR ")!=NULL) {
- if(strcmp(s,".")!=0 && strcmp(s,"..")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)s);
- } else
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)s);
- break;
- case DLG_HOST_NOS:
- if(strstr(szString,"Disk size")==NULL) {
- szString[13]=0; nRC=13;
- while((nRC=strlen(szString))>0 && szString[nRC-1]==' ')
- szString[nRC-1]=0;
- if(*szString!=0) {
- if(szString[strlen(szString)-1]=='/' ||
- szString[strlen(szString)-1]=='\\')
- {
- szString[strlen(szString)-1]=0;
- if(strcmp(szString,".")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
- } else
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
- }
- pStr=&szString[41]; nRC=13; pStr[nRC]=0;
- while((nRC=strlen(pStr))>0 && pStr[nRC-1]==' ')
- pStr[nRC-1]=0;
- if(*pStr!=0) {
- if(pStr[strlen(pStr)-1]=='/' ||
- pStr[strlen(pStr)-1]=='\\')
- {
- pStr[strlen(pStr)-1]=0;
- if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
- } else
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
- }
- }
- break;
- case DLG_HOST_SINTFTPD:
- case DLG_HOST_U5000:
- case DLG_HOST_UNIX:
- default:
- // assume UNIX ls format
- pStr=FindName(szString);
- // if line starts with 'd' its a directory
- if(strchr("dl",szString[0])!=NULL) {
- if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0)
- SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
- } else
- // if line starts with - or f its a file
- if(nHostType==(DLG_HOST_SINTFTPD-6000) ||
- strchr("-f",szString[0])!=NULL) {
- SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
- }
- break;
- }
- }
- fclose(fd);
- } else
- DoAddLine("couldn't open tmpfile for read.");
- } else
- DoPrintf("DoDirList returned %u",nRC);
- } // if we were connected
- return 0;
- }
-
- /*
- Read the output from HELP and see if we can determine the hosttype
- (if we don't already know it) and determine what functions are
- valid (things like mkdir, etc)
- */
- int ReadProcessHelp(SOCKET ctrl_socket)
- {
- int iRetCode;
-
- bCanMKD=bCanRMD=bCanREN=bCanDELE=FALSE;
-
- if(SendPacket(ctrl_socket,"HELP")!=-1) {
- iRetCode=ReadLine(ctrl_socket);
- if((iRetCode/100)==5 && nHostType==0) nHostType=DLG_HOST_NOS-6000;
- else {
- if(nHostType==0) {
- if(strstr(szMsgBuf,"NCSA")!=NULL ||
- strstr(szMsgBuf,"CUTCP")!=NULL)
- nHostType=DLG_HOST_NCSA-6000;
- else if(strncmp(szMsgBuf,"214-PC FTP server",17)==0 ||
- strstr(szMsgBuf,"QVT")!=NULL)
- nHostType=DLG_HOST_QVT-6000;
- else
- nHostType=DLG_HOST_UNIX-6000;
- }
- while((iRetCode!=421) && ((iRetCode/100)!=2 || szMsgBuf[3]=='-')) {
- if(strstr(szMsgBuf,"MKD")!=NULL) bCanMKD=TRUE;
- if(strstr(szMsgBuf,"RMD")!=NULL) bCanRMD=TRUE;
- if(strstr(szMsgBuf,"RNFR")!=NULL) bCanREN=TRUE;
- if(strstr(szMsgBuf,"DELE")!=NULL) bCanDELE=TRUE;
- iRetCode=ReadLine(ctrl_socket);
- }
- }
- }
- EnableWindow(hBtnRMKD,bCanMKD);
- EnableWindow(hBtnRRMD,bCanRMD);
- EnableWindow(hBtnRREN,bCanREN);
- EnableWindow(hBtnRDEL,bCanDELE);
- bHELP=TRUE;
- return iRetCode;
- }
-
- //*************************************************//
- // routines to load and save our list of hostnames //
- //*************************************************//
- int GPPS(LPSTR fldname,LPSTR deflt,LPSTR destination,int len) {
- return(GetPrivateProfileString(szAppName,fldname,
- deflt,destination,len,szIniFile));
- }
-
- void WPPS(LPSTR fldname,LPSTR value) {
- WritePrivateProfileString(szAppName,fldname,value,szIniFile);
- }
-
- void LoadUserInfo()
- {
- UINT flags;
- int nIndex;
- LPSTR s;
-
- GPPS("MAILADDR",NULL,szMailAddress,127);
- GPPS("VIEWER","notepad", szViewer,120);
- bAutoStart=GetPrivateProfileInt(szAppName, "AUTOSTART",
- bAutoStart,szIniFile);
- flags=GetPrivateProfileInt(szAppName,"FLAGS",
- 64+4+1,szIniFile);
- if(flags & 1) bRecvUniq=1; else bRecvUniq=0;
- if(flags & 2) bStorUniq=1; else bStorUniq=2;
- if(flags & 4) bBell=1; else bBell=0;
- if(flags & 8) bInteractive=1; else bInteractive=0;
- if(flags & 16) bVerbose=1; else bVerbose=0;
- if(flags & 32) bHash=1; else bHash=2;
- //if(flags & 64) bSendPort=1; else bSendPort=0;
- if(flags & 128) bDoGlob=1; else bDoGlob=2;
- for(nIndex=0;nIndex<MAXHOSTS;nIndex++) {
- wsprintf(szString,"HST%u",nIndex);
- if(GPPS(szString,NULL,szRemoteHost,79)>0) {
- if((s=strchr(szRemoteHost,' '))!=NULL) {
- *s++=0;
- nHostType=atoi(s);
- if((s=strchr(s,' '))!=NULL) {
- *s++=0;
- uiTimeOut=atoi(s);
- } else uiTimeOut=65;
- } else { nHostType=0; uiTimeOut=65;}
- szUserID[0]=0;
- wsprintf(szString,"UID%u",nIndex);
- GPPS(szString,NULL,szUserID,79);
- szPassWord[0]=0;
- wsprintf(szString,"PWD%u",nIndex);
- GPPS(szString,NULL,szPassWord,79);
- szInitDir[0]=0;
- wsprintf(szString,"DIR%u",nIndex);
- GPPS(szString,NULL,szInitDir,79);
- HostInfo[nIndex]=MakeInfo(szRemoteHost,szUserID,
- szPassWord,szInitDir,nHostType,1024,1024,uiTimeOut);
- } else HostInfo[nIndex]=NULL;
- }
- GPPS("HOSTNAME","129.29.64.246",szRemoteHost,79);
- GPPS("USERID","anonymous", szUserID, 80);
- szPassWord[0]=0; szInitDir[0]=0; uiTimeOut=65; nHostType=0;
- }
-
- void SaveUserInfo()
- {
- UINT flags;
- int nIndex;
-
- WPPS(NULL,NULL);
- WPPS("HOSTNAME",szRemoteHost);
- WPPS("USERID",szUserID);
- WPPS("MAILADDR",szMailAddress);
- WPPS("VIEWER",szViewer);
- wsprintf(szString,"%u",bAutoStart); WPPS("AUTOSTART",szString);
- flags=((bRecvUniq==1)?1:0) +
- // ((bStorUniq==1)?2:0) +
- ((bBell==1)?4:0) +
- ((bInteractive==1)?8:0)+
- // ((bHash==1)?32:0) +
- // ((bSendPort==1)?64:0) +
- // ((bDoGlob==1)?128:0) +
- ((bVerbose==1)?16:0);
- wsprintf(szString,"%u",flags); WPPS("FLAGS",szString);
- for(nIndex=0;nIndex<MAXHOSTS;nIndex++)
- if(GetInfo(HostInfo[nIndex],szRemoteHost,szUserID,szPassWord,szInitDir,
- &nHostType,NULL,NULL,&uiTimeOut)) {
- wsprintf(szString,"HST%u",nIndex);
- if(szRemoteHost[0]!=0) {
- wsprintf(szMsgBuf,"%s %u %u",szRemoteHost,nHostType,uiTimeOut);
- WPPS(szString,szMsgBuf);
- wsprintf(szString,"UID%u",nIndex);
- if(szUserID[0]!=0) WPPS(szString,szUserID);
- wsprintf(szString,"PWD%u",nIndex);
- if(szPassWord[0]!=0) WPPS(szString,szPassWord);
- wsprintf(szString,"DIR%u",nIndex);
- if(szInitDir[0]!=0) WPPS(szString,szInitDir);
- FreeInfo(HostInfo[nIndex]);
- HostInfo[nIndex]=0;
- }
- }
- }
-
-